package server;

// This file contains material supporting section 10.9 of the textbook:
// "Object Oriented Software Engineering" and is issued under the open-source
// license found at www.lloseng.com

/*
 * SimpleServer.java   2001-02-08
 *
 * Copyright (c) 2000 Robert Laganiere and Timothy C. Lethbridge.
 * All Rights Reserved.
 *
 */




import db.parking.beans.Complaints;
import db.parking.beans.Customer;
import db.parking.beans.Employee;
import db.parking.beans.Orders;
import db.parking.beans.ParkingLot;
import db.parking.beans.Subscriber;
import db.tables.AdminComplaints;
import db.tables.AdminCustomer;
import db.tables.AdminEmployee;
import db.tables.AdminOrders;
import db.tables.AdminSubscriber;
import db.tables.ParkingLotAdmin;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;
import java.awt.List;
import java.awt.Color;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;















import control.ConnectionManage;
import control.DBType;
import control.customTimestamp;
import client.Message;

/**
 * The <code> SimpleServer </code> class is a simple subclass of the
 * <code> ocsf.server.AbstractServer </code> class. It allows testing of the
 * functionalities offered by the OCSF framework. The
 * <code> java.awt.List </code> instance is used to display informative
 * messages. This list is red when the server is closed, yellow when the server
 * is stopped and green when open.
 * 
 * @author Dr. Robert Lagani&egrave;re
 * @version February 2001
 * @see ocsf.server.AbstractServer
 */
public class SimpleServer extends AbstractServer {
	private List liste;
	private Message msg;
	
	//for time stamp= server current time
	long time;// = System.currentTimeMillis();
	Timestamp currTimestamp;// = new Timestamp(time);
	

	/**
	 * Creates a simple server. The default port is 12345.
	 * 
	 * @param liste
	 *            the liste on which information will be displayed.
	 */
	public SimpleServer(List liste) {
		super(12345);
		this.liste = liste;
	}

	/**
	 * Creates a simple server.
	 * 
	 * @param port
	 *            the port on which the server will listen.
	 * @param liste
	 *            the liste on which information will be displayed.
	 */
	public SimpleServer(int port, List liste) {
		super(port);
		this.liste = liste;
	}

	/**
	 * Hook method called each time a new client connection is accepted.
	 * 
	 * @param client
	 *            the connection connected to the client.
	 */
	synchronized protected void clientConnected(ConnectionToClient client) {
		liste.add("Client connected: " + client);
		liste.makeVisible(liste.getItemCount() - 1);
	}

	/**
	 * Hook method called each time a client disconnects.
	 * 
	 * @param client
	 *            the connection with the client.
	 */
	synchronized protected void clientDisconnected(ConnectionToClient client) {
		liste.add("Client disconnected: " + client);
		liste.makeVisible(liste.getItemCount() - 1);
	}

	/**
	 * Hook method called each time an exception is thrown in a
	 * ConnectionToClient thread.
	 * 
	 * @param client
	 *            the client that raised the exception.
	 * @param Throwable
	 *            the exception thrown.
	 */
	synchronized protected void clientException(ConnectionToClient client,
			Throwable exception) {
		liste.add("Client exception: " + exception + " with " + client);
		liste.makeVisible(liste.getItemCount() - 1);
	}

	/**
	 * Hook method called when the server stops accepting connections because an
	 * exception has been raised.
	 * 
	 * @param exception
	 *            the exception raised.
	 */
	protected void listeningException(Throwable exception) {
		liste.add("Listening exception: " + exception);
		liste.makeVisible(liste.getItemCount() - 1);
		liste.setBackground(Color.red);
	}

	/**
	 * Hook method called when the server stops accepting connections.
	 */
	protected void serverStopped() {
		liste.add("Server stopped");
		liste.makeVisible(liste.getItemCount() - 1);
		liste.setBackground(Color.yellow);
	}

	/**
	 * Hook method called when the server is clased.
	 */
	protected void serverClosed() {
		liste.add("Server closed");
		liste.makeVisible(liste.getItemCount() - 1);
		liste.setBackground(Color.red);
	}

	/**
	 * Hook method called when the server starts listening for connections.
	 */
	protected void serverStarted() {
		liste.add("Server started on port : " + this.getPort());
		liste.add("Waiting for users to connect...");
		liste.makeVisible(liste.getItemCount() - 1);
		liste.setBackground(Color.green);
	}

	/**
	 * Handles a command sent from one client to the server.
	 * 
	 * @param msg
	 *            the message sent.
	 * @param client
	 *            the connection connected to the client that sent the message.
	 */
	protected void handleMessageFromClient(Object msg, ConnectionToClient client) {

		//System.out.println("server");
		ConnectionManage.getInstance().setDBType(DBType.MYSQL);
		this.msg = (Message) msg;
		//System.out.println(this.msg.getMsg());

		switch (this.msg.getMsg()) {
		// orders handle
		case "AddOccasionalOrder":
			AddOccasionalOrder(this.msg);
			break;

		case "AddTemporaryOrder":
			AddTemporaryOrder(this.msg);
			break;

		case "CancelOrder": {
			CancelOrder(this.msg);
			break;
		}

		case "SubmitComplaint": {
			SubmitComplaint(this.msg);
			break;
		}
		
		case "AddFullSubscriber": {
			AddFullSubscriber(this.msg);
			break;
		}
		
		case "AddRegularSubscriber": {
			AddRegularSubscriber(this.msg);
			break;
		}
		case "TrackOrder": {
			TrackOrder(this.msg);
			break;
		}
		case "Login": {
			Login(this.msg);
			break;
		}
		case "CheckInRegular": {
			CheckInRegular(this.msg);
			break;
		}
		case "CheckInSubscriber": {
			CheckInSubscriber(this.msg);
			break;
		}
		case "CheckOut": {
			CheckOut(this.msg);
			break;
		}
		
		case "GetComplaints": {
			GetComplaints(this.msg);
			break;
		}

		default:
			this.msg.setStatus(false);
		}

		sendToAllClients(this.msg);
	}

	private void GetComplaints(Object msg) {
		Message tempMsg = (Message) msg;
		ArrayList<Complaints> results = null;
		try{
			try {
				results = AdminComplaints.getAll(20,"DATE desc");
				if(results==null){
					tempMsg.setStatusMsg("There is no complaints yet..");
					System.out.println("No complaints :: debug");
				}				    
				else{
					tempMsg.setStatusMsg("OK");
					tempMsg.setMsg("GetComplaints");
					tempMsg.setObj(results);					
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
	}

	/****
	 * AddOccasionalOrder**
	 * 
	 * @param msg
	 * @return void Check user validity against DB and insert an occasional user
	 */
	private void AddOccasionalOrder(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Orders o = (Orders) tempMsg.getObj();

			// check if an Occasional customer with this ID exists
			Customer bean = AdminCustomer.getOccasionalRow(o.getUid(), o.getType());
			if (bean == null) {
				liste.add("ERROR:User Has Entered An Invalid ID");
				tempMsg.setStatusMsg("Such Occasional User Does Not Exist");
				return;
			}
			long time = System.currentTimeMillis();// Set current time at this
													// second to StartTime
			Timestamp currTimestamp = new Timestamp(time);
			o.setStartTime(currTimestamp);
			// check that entered leave time is not before the current time now
			if (currTimestamp.getTime() > o.getLeaveTime().getTime()) {
				liste.add("ERROR:Occaional User Has Entered Invalid Leave Time");
				tempMsg.setStatusMsg("Leave Time Must Be After Current Time");
				return;
			}
			// Check if lot if full
			ParkingLot lot = ParkingLotAdmin.getRow(o.getLotNo());
			if (lot.getTotalCars() >= lot.getCapacity()) {
				// TODO:direct client to alternative lot
				liste.add("ERROR:Parking Lot Is Full,Please Try Another Lot");
				tempMsg.setStatusMsg("Sorry,But This Parking Lot Is Full");
				return;
			}
			else
			{
				ParkingLotAdmin.update(lot.getLotID(), lot.getTotalCars() + 1);
			}
			
			if (AdminOrders.insertOccasional(o)) {
				tempMsg.setStatus(true); // insert to DB was
				liste.add("Occasional Client Has Added Order No." + o.getOid());
			} else {
				tempMsg.setStatus(false);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/****
	 * AddTemporaryOrder**
	 * 
	 * @param msg
	 * @return void Check user validity against DB and insert a temporary user
	 */
	private void AddTemporaryOrder(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Orders o = (Orders) tempMsg.getObj();

			// check if an Occasional customer with this ID exists
			Customer bean = AdminCustomer.getRow(o.getUid());
			if (bean == null) {
				liste.add("ERROR:User Has Entered An Invalid ID");
				tempMsg.setStatusMsg("Such Temporary User Does Not Exist");
				return;
			}
			long time = System.currentTimeMillis();// Set current time at this
													// second to StartTime
			Timestamp currTimestamp = new Timestamp(time);
			o.setStartTime(currTimestamp);
			// check that entered times are after current time
			if (currTimestamp.getTime() > o.getLeaveTime().getTime()
					&& currTimestamp.getTime() > o.getStartTime().getTime()) {
				liste.add("ERROR:Temporary User Has Entered Invalid Leave Time");
				tempMsg.setStatusMsg("Times must be aftr current time");
				return;
			}
			// Check if lot if full
			ParkingLot lot = ParkingLotAdmin.getRow(o.getLotNo());
			
			if (lot.getTotalCars() >= lot.getCapacity()) {
				// TODO:direct client to alternative lot
				liste.add("ERROR:Parking Lot Is Full,Please Try Another Lot");
				tempMsg.setStatusMsg("Sorry,But This Parking Lot Is Full");
				return;
			}
			else
				ParkingLotAdmin.update(o.getLotNo(), lot.getTotalCars() + 1);
				

			if (AdminOrders.insert((Orders) tempMsg.getObj())) {
				tempMsg.setStatus(true);
				liste.add("Temorary Client Has Added Order No."
						+ ((Orders) tempMsg.getObj()).getOid());
			} else {
				tempMsg.setStatus(false);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
	/****
	 * AddFullSubscriber**
	 * 
	 * @param msg
	 * @return void Add new Full subscription to DB
	 */
	private void AddFullSubscriber(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Subscriber s = (Subscriber) tempMsg.getObj();

			Customer bean = AdminCustomer.getRow(s.getCusID());
			if (bean == null) {
				liste.add("ERROR:User Has Entered An Invalid ID");
				tempMsg.setStatusMsg("Such Customer Does Not Exist");
				return;
			}
			
			long time = System.currentTimeMillis();// Set current time at this second to StartTime
			Timestamp currTimestamp = new Timestamp(time);
			// check that entered times are after current time
			if (currTimestamp.getTime() > s.getSubStart().getTime()) {
				liste.add("ERROR:Invalid Date Input was entered by subscriber");
				tempMsg.setStatusMsg("Times must be after current time");
				return;
			}
			
			if (AdminSubscriber.insertFull((Subscriber) tempMsg.getObj())) {
				tempMsg.setStatus(true);
				s.setStatus(0);
				liste.add("New Full Subscriber Has Been Added To The System.");
			} else {
				tempMsg.setStatus(false);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/****
	 * AddRegularSubscriber**
	 * 
	 * @param msg
	 * @return void Add new Regular subscription to DB
	 */
	private void AddRegularSubscriber(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Subscriber s = (Subscriber) tempMsg.getObj();
			Customer bean = AdminCustomer.getRow(s.getCusID());
			if (bean == null) {
				liste.add("ERROR:User Has Entered An Invalid ID");
				tempMsg.setStatusMsg("Such Customer Does Not Exist");
				return;
			}
	
			long time = System.currentTimeMillis();// Set current time at this second to StartTime
			Timestamp currTimestamp = new Timestamp(time);
			
			// check that entered times are after current time
			if (currTimestamp.getTime() > s.getSubStart().getTime()) {
				liste.add("ERROR:Invalid Date Input was entered by subscriber");
				tempMsg.setStatusMsg("Times must be after current time");
				return;
			}
			//Generate today's date to build Timestamp for today's leave time
			Calendar calendar = Calendar.getInstance();
			int day = calendar.get(Calendar.DAY_OF_WEEK); 
			int year = calendar.get(Calendar.YEAR); 
			int month = calendar.get(Calendar.MONTH); 
			
			Timestamp temp=customTimestamp.makeTimestamp(year,month,day,s.getTmp().getHours(),s.getTmp().getMinutes(),00,00);
			s.setLeaveTime(temp);
		
			if (AdminSubscriber.insertRegular((Subscriber) tempMsg.getObj())) {
				tempMsg.setStatus(true);
				s.setStatus(0);
				liste.add("New Regular Subscriber Has Been Added To The System.");
			} else {
				tempMsg.setStatus(false);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	/****
	 * CancelOrder**
	 * 
	 * @param msg
	 * @return void Check user validity against DB and insert a temporary user
	 */
	private void CancelOrder(Object msg) {
		// get current Timestamp of server
		long time = System.currentTimeMillis();
		Timestamp currTimestamp = new Timestamp(time);
		
		Message tempMsg = (Message) msg;
		Orders o = (Orders) tempMsg.getObj();//Get order object
		
		try {
			// find the customer order by id
			int id = o.getOid();

			// check if such order exists in DB and get it
			Orders tmpOrder = new Orders();
			tmpOrder = AdminOrders.getRow(id);
			if (tmpOrder == null) {
				liste.add("ERROR:User Has Entered An Invalid Order ID");
				tempMsg.setStatus(false);
				tempMsg.setStatusMsg("You Have Entered An Invalid Order ID");
				return;
			}
			// save user scheduled parking Timestamp
			Timestamp tmpParking = tmpOrder.getStartTime();
			// check if parking is being cancelled 3 hours(108000000
			// milliseconds) before its beginning
			if (tmpParking.getTime() + 10800000 < currTimestamp.getTime()) {
				// TODO:give money back to user (compensate 100%)
				//AdminCustomer.update(id, amountToGiveBack);
				
			} else if ((tmpOrder.getStartTime().getTime() - 108000000 < currTimestamp.getTime())
					&& (tmpOrder.getStartTime().getTime() - 3600000 > currTimestamp
							.getTime()))
			// user has canceled Order between 1-3 hours before beginning - 50%
			// fine is given to user(1 hour = 3600000ms)
			{
				// TODO:compensate 50%
				//AdminCustomer.update(id, amountToGiveBack);

			}
			
			// update number of users inside lot - Done In Object
			//ParkingLot lot = ParkingLotAdmin.getRow(o.getLotNo());
			//ParkingLotAdmin.update(o.getLotNo(), lot.getTotalCars() - 1); 	
			
			//Set order status to canceled
			tmpOrder.setStatus(2);
			AdminOrders.update(tmpOrder);
			// TODO:delete user from parking space inside lot (Parking)
			tempMsg.setStatus(true); // Order Cancellation was successful
			// TODO: tell user how much money he is getting back via Dialog
			liste.add("User has cancelled order No." + o.getOid());

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	
	/****
	 * SubmitComplaint**
	 * 
	 * @param msg
	 * @return void Check order validity against DB and insert a new complaint
	 */
	private void SubmitComplaint(Object msg) {
		long time = System.currentTimeMillis();		
		Timestamp currTimestamp = new Timestamp(time);
		Message tempMsg = (Message) msg;
		
		Complaints complaint=(Complaints) tempMsg.getObj();
		complaint.setTimestamp(currTimestamp);
		complaint.setStatus(0); 	//new complaint
		complaint.setAmount(0);


		int id = complaint.getOrderID();
		liste.add("insertComplait"+id);									
		Orders order = new Orders();
		try {
			order = AdminOrders.getRow(id); // get the order detail from data base
			if (order == null) {
				tempMsg.setStatusMsg("There Is no such id");
				liste.add("ERROR:User Has Entered An Invalid ID");
				return;
			}
			complaint.setCustomerID(order.getUid());
			AdminComplaints.insert(complaint);
			tempMsg.setStatusMsg("Your Complaint is Submitted, We will contact youas soon as possible");
			liste.add("user submitt complaint");
			tempMsg.setStatus(true); // Complaint was successful
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println(e.toString()+" SimpleServer->SubmitComplaint");
		}
	}
	
	
	/****
	 * TrackOrder**
	 * 
	 * @param msg
	 * @return void Get Tracking Information of Order
	 */
	private void TrackOrder(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Orders o = (Orders) tempMsg.getObj();

			Orders bean = AdminOrders.getRow(o.getOid());
			if (bean == null) {
				liste.add("ERROR:User Has Entered An Invalid Order ID");
				tempMsg.setStatusMsg("Such Order Does Not Exist");
				return;
			}
				tempMsg.setStatus(true);
				liste.add("User Requested Order Tracking Of Order No."+o.getOid());
				o.setStatus(bean.getStatus());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	/****
	 * Login**
	 * 
	 * @param msg
	 * @return void Authenticate Employee when Login into system occurs
	 */
	private void Login(Object msg) {
		Message tempMsg = (Message) msg;	
		Employee bean=null;
		try {
			Employee emp = new Employee();
			emp = (Employee) tempMsg.getObj();
			bean = AdminEmployee.getRow(emp.getUsername(),emp.getPassword());
			if(bean==null){
				tempMsg.setStatus(false);
	            tempMsg.setStatusMsg("Login Failed");
	            tempMsg.setMsg("Login");
			}else{
			//tempMsg.setStatus(true);
			//e.setType(bean.getType());
			//e.setEmpName(bean.getEmpName());
            tempMsg.setStatus(true);
            tempMsg.setStatusMsg("OK");
            tempMsg.setMsg("Login");
            tempMsg.setObj(bean);
			}
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	/****
	 * Check In Regular**
	 * 
	 * @param msg
	 * @return void Check In Regular Client Into System
	 */
	private void CheckInRegular(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Orders o = (Orders) tempMsg.getObj();
			
			long time = System.currentTimeMillis();
			Timestamp currTimestamp = new Timestamp(time);
			
			Orders bean = AdminOrders.getRow(o.getOid());
			if (bean == null) {
				liste.add("ERROR:This User ID Did Not Make Any Orders");
				tempMsg.setStatusMsg("Such Order Does Not Exist - CheckIn Aborted");
				return;
			}
			//Occasional user which is already parking
			if(bean.getType() == "Regular" && bean.getStatus() == 1)
			{
				liste.add("ERROR:This User Is Already Parking");
				tempMsg.setStatusMsg("You Can't CheckIn Twice,Sorry.");
				return;			
			}
			if(bean.getStatus() == 1)
			{
				liste.add("ERROR:User " + o.getUid() + " Tried To Login Twice");
				tempMsg.setStatusMsg("You Can't CheckIn Twice,Sorry.");
				return;			
			}
			if (currTimestamp.getTime() >  bean.getStartTime().getTime()) {
				//user is late for parking and receives a fine.
				//TODO : add fine.
			}
			ParkingLot lot = ParkingLotAdmin.getRow(bean.getLotNo());
			if (lot.getTotalCars() >= lot.getCapacity()) {
				// TODO:direct client to alternative lot
				liste.add("ERROR:Parking Lot Is Full,Please Try Another Lot");
				tempMsg.setStatusMsg("Sorry,But This Parking Lot Is Full");
				return;
			}
			else
				ParkingLotAdmin.update(lot.getLotID(), lot.getTotalCars() + 1);
			
			bean.setStatus(1); //change user status to active parking
			if(AdminOrders.update(bean))
			{
				tempMsg.setStatus(true);
				liste.add("User "+ o.getUid() +" Has Entered Lot No."+ bean.getLotNo());
			} else {
				tempMsg.setStatus(false);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	/****
	 * Check In Subscriber**
	 * 
	 * @param msg
	 * @return void Check In Subscriber Into System
	 */
	private void CheckInSubscriber(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Subscriber s = (Subscriber) tempMsg.getObj();
			
			long time = System.currentTimeMillis();
			Timestamp currTimestamp = new Timestamp(time);
			
			Subscriber bean = AdminSubscriber.getRow(s.getSubID(),s.getCarNo());
			if (bean == null) {
				liste.add("ERROR:Subscriber Does Not Exists");
				tempMsg.setStatusMsg("Such Subscription Does Not Exist- CheckIn Aborted");
				return;
			}
			//Occasional user which is already parking
			if(bean.getStatus() == 1)
			{
				liste.add("ERROR:Subscriber " + s.getSubID() + " Tried To Login Twice");
				tempMsg.setStatusMsg("You Can't CheckIn Twice,Sorry.");
				return;			
			}
			//if regular subcriber came after his leave time
			if ( (currTimestamp.getDate() == bean.getLeaveTime().getDate() ) &&  (currTimestamp.getTime() > bean.getLeaveTime().getTime() ) && (bean.getType() == "Regular") ) {
				liste.add("ERROR:Subscriber " + s.getSubID() + " Came After His Parking Hours");
				tempMsg.setStatusMsg("Sorry, But You Can't Park After Your Regular Park Time");
				return;	
			}
			//TODO: what happens to FULL subscriber -> lot is taken from object
		/*	ParkingLot lot = ParkingLotAdmin.getRow(bean.getLotNo());
			if (lot.getTotalCars() >= lot.getCapacity()) {
				// TODO:direct client to alternative lot
				liste.add("ERROR:Parking Lot Is Full,Please Try Another Lot");
				tempMsg.setStatusMsg("Sorry,But This Parking Lot Is Full");
				return;
			}
			else
				ParkingLotAdmin.update(lot.getLotID(), lot.getTotalCars() + 1);*/
			
			bean.setStatus(1); //change user status to active parking
			if(AdminSubscriber.update(bean))
			{
				tempMsg.setStatus(true);
				liste.add("Subscriber "+ s.getSubID() +" Has Entered Lot No."+ bean.getLotNo());
			} else {
				tempMsg.setStatus(false);
			}
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	/****
	 * Check In Subscriber**
	 * 
	 * @param msg
	 * @return void Check In Subscriber Into System
	 */
	private void CheckOut(Object msg) {
		Message tempMsg = (Message) msg;
		try {
			Orders o = (Orders) tempMsg.getObj();
			
			long time = System.currentTimeMillis();
			Timestamp currTimestamp = new Timestamp(time);
			
			//check if such subcriber exists
			Subscriber Sbean = AdminSubscriber.getRow(o.getUid(),o.getCarNo());
			if (Sbean == null) {
				Customer Cbean = AdminCustomer.getRow(o.getUid());
				if (Cbean == null) {
					liste.add("ERROR:Invalid User- - CheckOut Aborted");
					tempMsg.setStatusMsg("Such User Does Not Exist - CheckIn Aborted");
					return;
				}
				else{
					o.setType(Cbean.getType());
				}				
			}
			else
			{
				o.setType(Sbean.getType());
				
			}
			
			//get LotNumber and Decrement User From Lot
			ParkingLot lot = ParkingLotAdmin.getRow(o.getLotNo());
			
			//at this point we have user type in O object
			if(o.getType() == "Regular" || o.getType() == "Temporary")
			{
				
		    //if customer is leaving after scheduled leaveTime
				if ( (currTimestamp.getDate() == o.getLeaveTime().getDate() ) &&  (currTimestamp.getTime() > o.getLeaveTime().getTime())) {
					//TODO:add fine.
				}	
				//AdminOrders.update();
				ParkingLotAdmin.update(lot.getLotID(), lot.getTotalCars() -1);

			}

			else if(o.getType() == "Full" || o.getType() == "Regular"){
			    //if Subscriber is leaving after scheduled leaveTime
				if ( (currTimestamp.getDate() == o.getLeaveTime().getDate() ) &&  (currTimestamp.getTime() > o.getLeaveTime().getTime())) {
					//TODO:add fine.
				}	
					//Update Subscriber Parking Status As Done.
					AdminSubscriber.update(Sbean);
					ParkingLotAdmin.update(lot.getLotID(), lot.getTotalCars() -1);
			}
			
			
		/*	bean.setStatus(1); //change user status to active parking
			if(AdminSubscriber.update(bean))
			{
				tempMsg.setStatus(true);
				liste.add("Subscriber "+ s.getSubID() +" Has Entered Lot No."+ bean.getLotNo());
			} else {
				tempMsg.setStatus(false);
			}*/
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
  }
